import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PurchaseOrderVO, PurchaseOrderForm, PurchaseOrderQuery } from '@/api/erp/purchase/order/types';

/**
 * 查询采购订单列表
 * @param query
 * @returns {*}
 */

export const listPurchaseOrder = (query?: PurchaseOrderQuery): AxiosPromise<PurchaseOrderVO[]> => {
  return request({
    url: '/erp/purchaseOrder/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询采购订单详细
 * @param id
 */
export const getPurchaseOrder = (no: string | number): AxiosPromise<PurchaseOrderForm> => {
  return request({
    url: '/erp/purchaseOrder/' + no,
    method: 'get'
  });
};

/**
 * 新增采购订单
 * @param data
 */
export const addPurchaseOrder = (data: PurchaseOrderForm) => {
  return request({
    url: '/erp/purchaseOrder',
    method: 'post',
    data: data
  });
};

/**
 * 修改采购订单
 * @param data
 */
export const updatePurchaseOrder = (data: PurchaseOrderForm) => {
  return request({
    url: '/erp/purchaseOrder',
    method: 'put',
    data: data
  });
};

/**
 * 删除采购订单
 * @param id
 */
export const delPurchaseOrder = (id: string | number | Array<string | number>) => {
  return request({
    url: '/erp/purchaseOrder/' + id,
    method: 'delete'
  });
};

/**
 * 更新采购订单的状态
 * @param id
 */
export const updatePurchaseOrderStatus = (id: string | number | Array<string | number>, status: number) => {
  return request({
    url: `/erp/purchaseOrder/update-status`,
    method: 'put',
    params: {
      id,
      status
    }
  })
}
